package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.memorandum.CompleteMemorandumFormBean;
import com.info.zhiduoduo.admin.model.formbean.memorandum.QueryMemorandumByConditionFormBean;
import com.info.zhiduoduo.admin.model.formbean.memorandum.SaveMemorandumFormBean;
import com.info.zhiduoduo.admin.model.formbean.memorandum.UpdateMemorandumFormBean;
import com.info.zhiduoduo.admin.service.MemorandumService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.entity.memorandum.PlatformMemorandum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 备忘录管理
 *
 * @author cuichenglong
 * @since 2020/10/22 下午18:29
 */
@Api(tags = "备忘录接口")
@RestController
@RequestMapping("/memorandum")
public class MemorandumController {

    @Resource
    MemorandumService memorandumService;

    @ZddLog(name = "新增备忘录")
    @ApiOperation("新增备忘录")
    @PostMapping("/saveMemorandum")
    public SmartResult saveMemorandum(@RequestBody BaseSimpleFormBean<SaveMemorandumFormBean> formBean) {
        return memorandumService.saveMemorandum(formBean);
    }

    @ApiOperation("列表查询")
    @PostMapping("/queryMemorandumByCondition")
    public SmartResult queryMemorandumByCondition(@RequestBody BaseSimpleFormBean<QueryMemorandumByConditionFormBean> formBean) {
        return memorandumService.queryMemorandumByCondition(formBean);
    }

    @ApiOperation("根据ID查询开票详情")
    @PostMapping("/getMemorandumById")
    public SmartResult getMemorandumById(@RequestBody BaseSimpleFormBean<Integer> formBean) {
        return memorandumService.getMemorandumById(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "编辑备忘录",entities = @LogEntity(entity = PlatformMemorandum.class,parameters =
    @LogParameter(fields = "id",parameters = "formBean.reqdata.id")))
    @ApiOperation("编辑备忘录")
    @PostMapping("/updateMemorandum")
    public SmartResult updateMemorandum(@RequestBody BaseSimpleFormBean<UpdateMemorandumFormBean> formBean) {
        return memorandumService.updateMemorandum(formBean);
    }

    @ZddLog(type = ZddLogType.UPDATE,name = "完成备忘录",entities = @LogEntity(entity = PlatformMemorandum.class,parameters =
    @LogParameter(fields = "id",parameters = "formBean.reqdata.id")))
    @ApiOperation("完成备忘录")
    @PostMapping("/completeMemorandum")
    public SmartResult completeMemorandum(@RequestBody BaseSimpleFormBean<CompleteMemorandumFormBean> formBean) {
        return memorandumService.completeMemorandum(formBean);
    }
}
